﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net.Sockets;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace BACKOFFICE
{
    public partial class Form1 : DevExpress.XtraEditors.XtraForm
    {
        public static Thread UpdateProcedures;

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            xtraScrollableControl1.Controls.Add(new HomeScreen());

            

            StaticProperties.TimeToUpdate = .25;

            UpdateProcedures = new Thread(new ThreadStart(UpdateProcedures1));
            UpdateProcedures.Name = "UPDATE THREAD";
            timer1.Interval = Convert.ToInt32(TimeSpan.FromMinutes(StaticProperties.TimeToUpdate).TotalMilliseconds);
            UpdateProcedures.Start();
        }

        private void Form1_NewFileRecieved(object sender, string filename)
        {
            this.BeginInvoke(new Action(delegate()
                {
                    MessageBox.Show("New File Recieved\n" + filename);
                    System.Diagnostics.Process.Start("explorer", @"C:\");
                }
            ));
        }

        private void UpdateProcedures1()
        {
            timer1.Start();

            FileSendRecieveClass.RecieveFiles NewReciever = new FileSendRecieveClass.RecieveFiles();
            NewReciever.StartListeningForFiles();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            //bool IsThereSqlConnection = DataTableClass.IsServerConnected();

            //try
            //{
            //    DataTableClass.SendDataToSqlServer(DataTableClass.Receipt.TableName);
            //    DataTableClass.SendDataToSqlServer(DataTableClass.EmployeeLogin.TableName);
            //    DataTableClass.SendDataToSqlServer(DataTableClass.EmployeeInfo.TableName);
            //    DataTableClass.SendDataToSqlServer(DataTableClass.EmployeeTimeSheet.TableName);
            //    DataTableClass.SendDataToSqlServer(DataTableClass.EmployeeSchedule.TableName);
            //    //MessageBox.Show("UPDATE OCCURED");
            //    DataTableClass.SendDataToSqlServer(DataTableClass.JobTitles.TableName);
            //    DataTableClass.SendDataToSqlServer(DataTableClass.MenuItemsCategory.TableName);
            //    DataTableClass.SendDataToSqlServer(DataTableClass.MenuItems.TableName);
            //    DataTableClass.SendDataToSqlServer(DataTableClass.ReceiptData.TableName);
            //    DataTableClass.SendDataToSqlServer(DataTableClass.PaymentTypes.TableName);

            //}
            //catch(Exception E)
            //{
            //    MessageBox.Show(E.ToString());
            //    DataTableClass.SaveDataSetToFile(DataTableClass.EmployeeLogin);
            //    DataTableClass.SaveDataSetToFile(DataTableClass.EmployeeInfo);
            //    DataTableClass.SaveDataSetToFile(DataTableClass.EmployeeTimeSheet);
            //    DataTableClass.SaveDataSetToFile(DataTableClass.EmployeeSchedule);

            //    DataTableClass.SaveDataSetToFile(DataTableClass.JobTitles);
            //    DataTableClass.SaveDataSetToFile(DataTableClass.MenuItemsCategory);
            //    DataTableClass.SaveDataSetToFile(DataTableClass.MenuItems);
            //    DataTableClass.SaveDataSetToFile(DataTableClass.Receipt);
            //    DataTableClass.SaveDataSetToFile(DataTableClass.ReceiptData);
            //    DataTableClass.SaveDataSetToFile(DataTableClass.PaymentTypes);
            //}
            //finally
            //{
            //    if (IsThereSqlConnection)
            //    {
            //        DataTableClass.EmployeeLogin.Clear();
            //        DataTableClass.LoadDataTable("EmployeeLogin", DataTableClass.EmployeeLogin);
            //        DataTableClass.EmployeeInfo.Clear();
            //        DataTableClass.LoadDataTable("EmployeeInfo", DataTableClass.EmployeeInfo);
            //        DataTableClass.EmployeeTimeSheet.Clear();
            //        DataTableClass.LoadDataTable("EmployeeTimeSheet", DataTableClass.EmployeeTimeSheet);
            //        DataTableClass.EmployeeSchedule.Clear();
            //        DataTableClass.LoadDataTable("EmployeeTimeSheet", DataTableClass.EmployeeSchedule);
            //        DataTableClass.JobTitles.Clear();
            //        DataTableClass.LoadDataTable("JobTitles", DataTableClass.JobTitles);
            //        DataTableClass.MenuItemsCategory.Clear();
            //        DataTableClass.LoadDataTable("MenuCategory", DataTableClass.MenuItemsCategory);
            //        DataTableClass.LoadMenuCategoryDictionary();
            //        DataTableClass.MenuItems.Clear();
            //        DataTableClass.LoadDataTable("MenuItems", DataTableClass.MenuItems);
            //        DataTableClass.LoadMenuItemsDictionary();
            //        DataTableClass.Receipt.Clear();
            //        DataTableClass.LoadDataTable("Receipt", DataTableClass.Receipt);
            //        DataTableClass.ReceiptData.Clear();
            //        DataTableClass.LoadDataTable("ReceiptData", DataTableClass.ReceiptData);
            //        DataTableClass.PaymentTypes.Clear();
            //        DataTableClass.LoadDataTable("PaymentTypes", DataTableClass.PaymentTypes);
            //    }
            //    else
            //    {

            //    }
            //}

        }

        private void xtraScrollableControl1_Click(object sender, EventArgs e)
        {

        }

        private void barButtonItem2_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            xtraScrollableControl1.Controls.Clear();
            xtraScrollableControl1.Controls.Add(new MenuSetup());
        }

        private void barButtonItem3_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            xtraScrollableControl1.Controls.Clear();
            xtraScrollableControl1.Controls.Add(new SeatingChart());
        }

        private void barButtonItem1_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            xtraScrollableControl1.Controls.Clear();
            xtraScrollableControl1.Controls.Add(new EmployeeSchedule());
        }



    }
}
